package com.yunxi.module.system.service.mail.impl;

import com.yunxi.module.system.mapper.mail.MailAccountMapper;
import com.yunxi.module.system.model.mail.MailAccountDO;
import com.yunxi.module.system.redis.RedisKeyConstants;
import com.yunxi.module.system.service.mail.MailAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

/**
 * <p>
 * 邮箱账号 Service 接口实现类
 * </p>
 *
 * @author lidy
 * @since 2024-05-08
 */
@Service
@Validated
@Slf4j
public class MailAccountServiceImpl implements MailAccountService {

    @Resource
    private MailAccountMapper mailAccountMapper;

    /**
     * 从缓存中获取邮箱账号信息
     *
     * @param accountId 邮箱编号
     * @return 邮箱账号信息
     */
    @Override
    @Cacheable(value = RedisKeyConstants.MAIL_ACCOUNT, key = "#accountId", unless = "#result == null")
    public MailAccountDO getMailAccountFromCache(Long accountId) {
        return getMailAccount(accountId);
    }

    /**
     * 获取邮箱账号信息
     *
     * @param accountId 邮箱编号
     * @return 邮箱账号信息
     */
    @Override
    public MailAccountDO getMailAccount(Long accountId) {
        return mailAccountMapper.selectById(accountId);
    }
}
